unit FindTruck;

interface

uses
  Winapi.Windows, Winapi.Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIForm, uniDBComboBox, uniDBLookupComboBox, uniMultiItem,
  uniComboBox, DB, DBClient, ClientRowSet, uniBasicGrid, uniDBGrid, uniButton,
  uniBitBtn, uniLabel, uniPanel, uniGUIBaseClasses, uniStatusBar, Clipbrd;

type
  TFrmFindTruck = class(TUniForm)
    UniStatusBar1: TUniStatusBar;
    UniPanel1: TUniPanel;
    UniLabel1: TUniLabel;
    btFind: TUniBitBtn;
    btConfirm: TUniBitBtn;
    UniDBGrid1: TUniDBGrid;
    crsTruck: TClientRowSet;
    crsTruckTRUCK_ID: TStringField;
    crsTruckLICENSE: TStringField;
    crsTruckLINE_CODE: TStringField;
    crsTruckLINE_NAME: TStringField;
    crsTruckOPT_CODE: TIntegerField;
    crsTruckOPT_CAP: TStringField;
    crsTruckSTATE: TIntegerField;
    crsTruckSTATE_CAP: TStringField;
    crsTruckBATCH_NO: TStringField;
    crsTruckTCK_TYPE: TIntegerField;
    crsTruckTCK_TYPECAP: TStringField;
    crsTruckOIL_CARD: TStringField;
    crsTruckTCK_LOAD: TFloatField;
    crsTruckMILEAGE: TFloatField;
    crsTruckBUY_DATE: TStringField;
    crsTruckENGINE_NO: TStringField;
    crsTruckCHASSIS_NO: TStringField;
    crsTruckINSURANCE: TStringField;
    crsTruckINSURE_TYPE: TStringField;
    crsTruckCK_DATE: TStringField;
    crsTruckRP_DATE: TStringField;
    crsTruckBRAND: TStringField;
    crsTruckMOTORCYCLE: TStringField;
    crsTruckPICTURE: TStringField;
    crsTruckDRV_NAME: TStringField;
    crsTruckDRV_TEL: TStringField;
    crsTruckREMARK: TStringField;
    crsTruckGROUP_CODE: TStringField;
    crsTruckNODE_NO: TStringField;
    crsTruckNODE_NAME: TStringField;
    crsTruckUSER_NO: TStringField;
    crsTruckSEAT_CNT: TIntegerField;
    crsTruckUSE_SEATCNT: TIntegerField;
    crsTruckUSE_LOAD: TFloatField;
    crsTruckSYS_ACCOUNT: TStringField;
    crsTruckUPDATETIME: TStringField;
    crsTruckDRV_LICENSE: TStringField;
    crsTruckDRV_CARD: TStringField;
    crsTruckLONGITUDE: TStringField;
    crsTruckLATITUDE: TStringField;
    crsTruckPOS_NODE: TStringField;
    crsTruckMANANGER: TStringField;
    crsTruckVERSION: TIntegerField;
    crsTruckENB_LOAD: TFloatField;
    dsTruck: TDataSource;
    cbStatus: TUniComboBox;
    UniLabel2: TUniLabel;
    cbLine: TUniDBLookupComboBox;
    UniLabel3: TUniLabel;
    cbClass: TUniDBLookupComboBox;
    dsLine: TDataSource;
    dsClass: TDataSource;
    procedure UniFormShow(Sender: TObject);
    procedure btFindClick(Sender: TObject);
    procedure cbLineKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure cbClassKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btConfirmClick(Sender: TObject);
    procedure UniDBGrid1ColumnSort(Column: TUniDBGridColumn;
      Direction: Boolean);
    procedure UniDBGrid1CellClick(Column: TUniDBGridColumn);
    procedure UniDBGrid1DblClick(Sender: TObject);
    procedure UniFormCreate(Sender: TObject);
  private
    { Private declarations }
    currField: TField;
  public
    { Public declarations }
    dsOrder:TDataset;
    procedure ShowTruck;
  end;

function FrmFindTruck: TFrmFindTruck;

implementation

{$R *.dfm}

uses
  MainModule, uniGUIApplication, ExpModule,dictModule, uCommFunction;

function FrmFindTruck: TFrmFindTruck;
begin
  Result := TFrmFindTruck(UniMainModule.GetFormInstance(TFrmFindTruck));
end;

{ TFrmFindTruck }

procedure TFrmFindTruck.btConfirmClick(Sender: TObject);
begin
  if self.dsOrder <> nil then
  with dsOrder do
  begin
    Edit;
    FieldByName('TSP_PNTNO').AsString  := dsTruck.DataSet.FieldByName('SYS_ACCOUNT').AsString;
    FieldByName('TSP_GROUP').AsString := dsTruck.DataSet.FieldByName('GROUP_CODE').AsString;
    FieldByName('TSP_NODE').AsString  := dsTruck.DataSet.FieldByName('NODE_NO').AsString;
    FieldByName('TSP_EMPTEL').AsString   := dsTruck.DataSet.FieldByName('DRV_TEL').AsString;
    FieldByName('TSP_EMPNAME').AsString   := dsTruck.DataSet.FieldByName('DRV_NAME').AsString;
  end;
  self.Close;

end;

procedure TFrmFindTruck.btFindClick(Sender: TObject);
begin
  ShowTruck;
end;

procedure TFrmFindTruck.cbClassKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_back then cbClass.ItemIndex := -1;

end;

procedure TFrmFindTruck.cbLineKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_back then cbLine.ItemIndex := -1;

end;

procedure TFrmFindTruck.ShowTruck;
var
  sqltxt:String;
begin
  sqltxt := 'select * from BAS_TRUCK '
          + 'where sys_account=' + quotedstr(dmexpress.UserInfo.SysAccount);

  if cbStatus.Text <> '' then
  begin
    sqltxt := sqltxt + ' and STATE=' + inttostr(cbStatus.ItemIndex+1);
  end;

  if cbLine.ItemIndex >= 0 then
    sqltxt := sqltxt + ' and LINE_NAME=' + quotedstr(cbLine.Text);

  if cbClass.ItemIndex >= 0 then
    sqltxt := sqltxt + ' and BATCH_NO=' + quotedstr(cbClass.Text);

  crsTruck.Close;
  crsTruck.CommandText := sqltxt;
  crsTruck.Open;

end;

procedure TFrmFindTruck.UniDBGrid1CellClick(Column: TUniDBGridColumn);
begin
  currField := Column.Field;
end;

procedure TFrmFindTruck.UniDBGrid1ColumnSort(Column: TUniDBGridColumn;
  Direction: Boolean);
begin
  SortColumn((UniDBGrid1.DataSource.DataSet as TClientRowSet), Column.FieldName, Direction);
end;

procedure TFrmFindTruck.UniDBGrid1DblClick(Sender: TObject);
begin
  if currField <> nil then
    Clipboard.AsText := currField.AsString;
end;

procedure TFrmFindTruck.UniFormCreate(Sender: TObject);
begin
  SetCompoentLanguage(Self);
end;

procedure TFrmFindTruck.UniFormShow(Sender: TObject);
begin
  if not crsTruck.Active then ShowTruck;
  SetFieldsSort(UniDBGrid1);
  currField := nil;
end;

end.
